// var id = 1;
var uname;
var content;
$.ajax({
    url: 'http://localhost:8888/api/articles/1/comments',
    success: function( res) {
        // console.log(res)
        res.data.reverse();
        var html = template('tpl-liuyan', res);
        
        $('.ping').html(html);
        uname = res.data[0].uname;
    }
})
$('textarea').on('input', function() {
    var count = $(this).val().trim();
    $('.word_count i').html(count.length)
    content = count;
})
$('.form button').on('click', function() {
    $.ajax({
        type: 'POST',
        url: 'http://localhost:8888/api/articles/1/comments',
        data: {uname, content},
        success: function(res) {
            if(res.status === 0) {
                alert('确定发布')
                $.ajax({
                    url: 'http://localhost:8888/api/articles/1/comments',
                    success: function( res) {
                        res.data.reverse();
                        var html = template('tpl-liuyan', res);
                        $('textarea').val('');
                        $('.ping').prepend(html);
                        uname = res.data[0].uname;
                    }
                })
            }
        }
    })
    return false;
})